<template>
  <div class="all">
    <header>
      <div class="div" @click="back">
        <img src="../../assets/返回.png" alt="">
        <span class="solid">返回</span>
      </div>
      <div class="div">
        <span>选择新团队长</span>
      </div>
      <div class="div">
        <span></span>
      </div>
    </header>
    <div class="box"
         @click="changeTeamLeader(item)"
         v-for="(item, index) in teamDoctorList.doctor" :key="index">
      <ul>
        <li>
          <img v-if="item.PHOTO" class="photo" :src="item.PHOTO" alt="">
          <img v-else class="photo" src="../../assets/男医生@2x.png" alt="">
        </li>
        <li>{{item.NICK_NAME}}</li>
        <li>
          <img class="selectImg" v-if="team_USER_ID === item.USER_ID" src="../../assets/题目选择.png" alt="">
          <img class="selectImg" v-else src="../../assets/题目未选择.png" alt="">
        </li>
      </ul>
    </div>
    <button class="keepButton" @click="queRen()">确认</button>
    <van-dialog v-model="transferLeaderShow"
                width="80%"
                confirm-button-color="#1da4f2"
                :title="`您确认要移交团队长为[` + ITEM.NICK_NAME +`]吗？`"
                @confirm="transferLeaderConfirm()"
                show-cancel-button>
    </van-dialog>
  </div>
</template>

<script>
import {Toast} from 'vant'
export default {
  name: 'NewTeamLeader',
  data () {
    return {
      id: this.$route.query.id,
      teamDoctorList: [],
      team_USER_ID: '',
      transferLeaderShow: false,
      ITEM: []
    }
  },
  mounted () {
    this.getTeamDetail()
  },
  methods: {
    queRen () {
      if (this.team_USER_ID === this.teamDoctorList.USER_ID) {
        // Toast('')
      } else {
        this.transferLeaderShow = true
      }
    },
    // 更改团队长
    changeTeamLeader (item) {
      this.team_USER_ID = item.USER_ID
      this.ITEM = item
      // this.transferLeaderShow = true
    },
    // 移交确认按钮
    transferLeaderConfirm () {
      this.$http.exitTeamDuiZhang({id: this.id, manager_doc_user_id: this.ITEM.USER_ID})
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            Toast('移交成功')
            this.MenuOnchange()
          } else {
            Toast(res.data.msg)
          }
        })
        .catch(err => {
          console.log(err)
          Toast('您的网络有些拥挤，请稍后再试')
        })
    },
    // 获取团队详情
    getTeamDetail () {
      this.$http.Teamdetail({id: this.id})
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            this.team_USER_ID = res.data.data.USER_ID
            this.teamDoctorList = res.data.data
          } else {
            Toast(res.data.msg)
          }
        })
        .catch(err => {
          console.log(err)
          Toast('您的网络有些拥挤，请稍后再试')
        })
    },
    // 返回
    back () {
      this.$router.history.go(-1)
    }
  }
}
</script>

<style scoped>
.all{
  width: 100%;
  height: 100%;
  background: #FAF9FE;
  overflow: auto;
  font-size: 15px;
  font-family: PingFang SC;
}
header{
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #E5E5E5;
  background: white;
  position: sticky;
  top: 0;
  z-index: 9;
}
.div{
  width: 33%;
  height: 100%;
  display: flex;
  align-items: center;
  font-family: "PingFang SC";
  font-size: 15px;
  font-weight: bold;
}
.div img{
  margin-right: 5px;
}
.div:nth-child(1) img{
  height: 13px;
  width: 7px;
  margin-left: 15px;
}
.div:nth-child(3) img{
  margin-right: 5px;
  width: 13px;
  height: 13px;
}
.div:nth-child(3) span{
  margin-right: 15px;
}
.div:nth-child(2){
  justify-content: center;
}
.div:nth-child(3){
  justify-content: flex-end;
}
.solid{
  color: #1DA4F2;
}
.box{
  width: 100%;
  padding: 0 15px;
  box-sizing: border-box;
  background: #FFFFFF;
}
.box ul {
  width: 100%;
  height: 60px;
  border-bottom: 1px solid #E5E5E5;
  display: flex;
  align-items: center;
  font-size: 15px;
  font-family: PingFang SC;
  font-weight: bold;
  color: #333333;
}
.box ul li:nth-child(2) {
  width: 80%;
  margin-left: 10px;
}
.photo{
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}
.selectImg{
  width: 16px;
  height: 16px;
}
.keepButton{
  width: 92%;
  height: 44px;
  background: linear-gradient(90deg, #1DA3F2 0%, #1DC7F2 100%);
  border-radius: 22px;
  color: #FFFFFF;
  border: none;
  margin: 10px 3%;
  font-size: 17px !important;
  font-weight: bold;
  position: absolute;
  bottom: 0;
}
</style>
